package com.huluobo.a2204kotlinshopping.mine

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.blankj.utilcode.util.ToastUtils
import com.huluobo.a2204kotlinshopping.R
import com.huluobo.a2204kotlinshopping.databinding.ActivityAddressBinding
import com.huluobo.base.view.BaseMVVMActivity

class AddressActivity : BaseMVVMActivity<ActivityAddressBinding, MineViewModel>() {
    override fun initData() {
        viewModel.updateAddressSuccess.observe(this) {
            ToastUtils.showLong(it.message)
            if (it.code == 200) {
                finish()
            }
        }
        viewModel.updateAddressFailed.observe(this) {
            Log.i("TagA", "更新地址失败")
        }
    }

    override fun initView() {
        dataBinding.addressBtn.setOnClickListener {
            viewModel.updateAddress(
                dataBinding.addressEt.text.toString()
            )
        }
    }

    override fun getViewModel(): Class<MineViewModel> {
        return MineViewModel::class.java
    }

    override fun getLayoutId(): Int = R.layout.activity_address
}